import 'package:vdrag_saas/config.dart';

class ItemModel {
  int? id;
  String? itemName;
  String imgUrl = '';
  int? likeRecord;
  int? browseRecord;
  String? description;
  List<String> labelArr = [];
  /// 封面
  String coverImage = "";

  ItemModel();
  static fromJson(Map<String, dynamic> json) {
    ItemModel item = ItemModel();
    item.id = json['id'];
    var attr = json['attributes'];
    item.itemName = attr['name'];
    item.description = attr['description'];
    item.likeRecord = attr['like_count'];
    item.browseRecord = attr['view_count'];
    // item.imgUrl = attr['cover']['data']['attributes']['formats']['thumbnail']['url'];
    List<Map<String, dynamic>> tagList = List<Map<String, dynamic>>.from(attr['tags']['data'] ?? []);
    List<String> tags = [];
    for (var element in tagList) {
      tags.add(element['attributes']['name']);
    }
    var coverImage =  attr['cover']['data'];
    if (coverImage != null) {
      item.coverImage = HttpConfig.baseUrl + coverImage['attributes']['url'];
    }
    item.labelArr = tags;
    return item;
  }
}
